package com.newtouch.bxzs.enterprise.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.newtouch.bxzs.common.base.BaseErrorEnum;
import com.newtouch.bxzs.common.base.BaseException;
import com.newtouch.bxzs.common.base.constant.RabbitMQConstant;
import com.newtouch.bxzs.common.base.em.*;
import com.newtouch.bxzs.common.base.model.AcceptionCustomerRecord;
import com.newtouch.bxzs.common.base.model.EnterpriseCustomer;
import com.newtouch.bxzs.common.base.model.PersonalCustomer;
import com.newtouch.bxzs.common.base.model.bo.PushMessageBO;
import com.newtouch.bxzs.common.base.util.*;
import com.newtouch.bxzs.enterprise.mapper.*;
import com.newtouch.bxzs.enterprise.model.bo.*;
import com.newtouch.bxzs.enterprise.model.vo.*;
import com.newtouch.bxzs.enterprise.service.AcceptionCustomerService;
import com.newtouch.bxzs.enterprise.service.PushCustomerService;
import com.newtouch.bxzs.enterprise.service.RelationShipService;
import com.newtouch.bxzs.enterprise.util.FieldCheckUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.client.RestTemplate;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * 客户接收ServiceImp类
 * <p>
 * <b>History:</b>
 * <table border="1">
 * <tr>
 * <th>Date</th>
 * <th>Operator</th>
 * <th>Memo</th>
 * </tr>
 * <tr>
 * <td>2021/1/12 14:12</td>
 * <td>Amour</td>
 * <td>Create</td>
 * </tr>
 * </table>
 *
 * @author Amour
 * @version 1.0.0
 * @since 1.0.0
 */
@Service
public class AcceptionCustomerServiceImpl implements AcceptionCustomerService {

    private static final Log logger = LogFactory.getLog(AcceptionCustomerServiceImpl.class);

    @Autowired
    private AcceptionCustomerRecordMapper acceptionCustomerRecordMapper;

    @Autowired
    private PersonalCustomerMapper personalCustomerMapper;

    @Autowired
    private PushCustomerRecordProductMapMapper pushProductMapper;

    @Autowired
    AmqpTemplate rabbitTemplate;

    @Autowired
    PushCustomerService pushCustomerService;

    @Autowired
    private RelationShipService relationShipService;

    @Autowired
    private CooperationCompanyUtils cooperationCompanyUtils;

    @Autowired
    private RedisUtils redisUtils;

    @Autowired
    ConferenceMapper conferenceMapper;

    @Autowired
    ActivityMapper activityMapper;

    @Autowired
    EnterpriseCustomerMapper enterpriseCustomerMapper;

    private final static String JUMP_TO_SHARE = "JUMP_TO_SHARE";
    private final static String JUMP_TO_APP = "JUMP_TO_APP";
    private final static String JUMP_TO_OTHER = "JUMP_TO_OTHER";

    @Override
    public Page<AcceptionCustomerRecordBO> getReceiveList(CustomerCndVO customerCnd) {
        logger.info("执行getReceiveList()获取接收列表信息");
        if (StringUtils.isEmpty(UserDetailUtil.getUserDetail().getUserJobNumber())){
            throw new BaseException(BaseErrorEnum.USER_NOT_EXISTS);
        }
        customerCnd.setUserJobNumber(UserDetailUtil.getUserDetail().getUserJobNumber());
        Page<AcceptionCustomerRecordBO>page = new Page<>(customerCnd.getCurrentPage(),customerCnd.getPageSize());
        if (PushSourceEnum.POLICY_INTENTION_PUSH.getCode().equals(customerCnd.getPushSource())){
            //判断客户推送来源是否为保单服务意向推送
            if (customerCnd.getPushStartTime() != null && customerCnd.getPushEndTime() != null){
                FieldCheckUtils.checkPolicyPush(customerCnd.getPushStartTime(),customerCnd.getPushEndTime(),
                        customerCnd.getPolicyNumber(),customerCnd.getCustomerCertificateType(),
                        customerCnd.getCustomerCertificateNumber());
                customerCnd.setPushStartTime(DateUtil.beginOfDay(customerCnd.getPushStartTime()));
                customerCnd.setPushEndTime(DateUtil.endOfDay(customerCnd.getPushEndTime()));
            }else {
                //推送查询条件默认为当前时间-7
                customerCnd.setPushStartTime(DateUtil.beginOfDay(DateUtil.offsetDay(new Date(),-7)));
                customerCnd.setPushEndTime(DateUtil.endOfDay(new Date()));
            }
            return acceptionCustomerRecordMapper.getAcceptPolicy(page,customerCnd,PushStatusEnum.WITHDRAW.getCode());
        }
        page = acceptionCustomerRecordMapper.getReceiveList(page,customerCnd,PushStatusEnum.WITHDRAW.getCode(),PushStatusEnum.HANDLED.getCode());
        page.setTotal(page.getRecords().size());
        return page;
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public String receiveCustomer(AcceptionCustomerVO acceptionCustomerVO) {
        logger.info("receiveCustomer()接收客户");
        String url;
        if (!PushStatusEnum.RECEIVED.getCode().equals(acceptionCustomerVO.getPushCustomerStatus())){
            //客户推送状态不为已接受，则仅修改双端客户推送状态不做其他操作
            url = getUrl(acceptionCustomerVO.getAccetptionCustomerRecordId(),
                    CompanyParameterTypeEnum.RECEPTION_PUSH_FEEDBACK.getCode(),
                    SystemParamsEnum.RECEPTION_PUSH_FEEDBACK.getCode());
            RevocationCustomerBO revocationCustomer = new RevocationCustomerBO(acceptionCustomerVO.getPushCustomerRecordId(),
                    acceptionCustomerVO.getPushCustomerStatus());
            //发送http请求给对端
            SendHttpRequestUtils<RevocationCustomerBO> sendHttpRequestUtils = new SendHttpRequestUtils<>();
            ReceiveCustomerBO receiveCustomer = JSON.toJavaObject(sendHttpRequestUtils.sendHttpRequestToJson(revocationCustomer, url),ReceiveCustomerBO.class);
            if (!receiveCustomer.getSuccessLogo()){
                throw new BaseException("-1", "修改失败");
            }else {
                //修改本端客户推送状态
                AcceptionCustomerRecord acceptionCustomerRecord = new AcceptionCustomerRecord();
                acceptionCustomerRecord.setUpdateStatus(acceptionCustomerVO.getAccetptionCustomerRecordId(),acceptionCustomerVO.getPushCustomerStatus(),
                        UserDetailUtil.getUserDetail().getUserId(),new Date());
                int updateCount = acceptionCustomerRecordMapper.updateById(acceptionCustomerRecord);
                if (updateCount <= 0){
                    throw new BaseException("-1", "修改失败");
                }else {
                    return "修改成功";
                }
            }
        }else {
            //接收客户时判断是否有三方关系
            BeanUtils.copyProperties(UserDetailUtil.getUserDetail(),acceptionCustomerVO);
            UserRelationShipVO userRelationShip = new UserRelationShipVO();
            BeanUtils.copyProperties(acceptionCustomerVO,userRelationShip);
            BeanUtils.copyProperties(acceptionCustomerRecordMapper.selectById(acceptionCustomerVO.getAccetptionCustomerRecordId()),
                    userRelationShip);
            boolean existRelationShip = relationShipService.isExistRelationShip(userRelationShip);
            //获取对端接收客户反馈接口url
            url = getUrl(acceptionCustomerVO.getAccetptionCustomerRecordId(),
                    CompanyParameterTypeEnum.RECEPTION_PUSH_FEEDBACK.getCode(),
                    SystemParamsEnum.RECEPTION_PUSH_FEEDBACK.getCode());
            //发送接收消息至对端
            ReceiveRelationShipVO receiveRelationShipVO = new ReceiveRelationShipVO(existRelationShip,acceptionCustomerVO.getPushCustomerRecordId(),
                    acceptionCustomerVO.getCustomerId(),acceptionCustomerVO.getPushCustomerStatus(),
                    acceptionCustomerVO.getUnifiedSocialCreditCode());
            //发送http请求
            SendHttpRequestUtils<ReceiveRelationShipVO> sendHttpRequestUtils = new SendHttpRequestUtils<>();
            ReceiveCustomerBO receiveCustomer = JSON.toJavaObject(sendHttpRequestUtils.sendHttpRequestToJson(receiveRelationShipVO, url),ReceiveCustomerBO.class);
            //修改客户接受表接收状态
            AcceptionCustomerRecord acceptionCustomerRecord = new AcceptionCustomerRecord();
            BeanUtils.copyProperties(acceptionCustomerVO,acceptionCustomerRecord);
            if (receiveCustomer.getSuccessLogo() == null){
                throw new BaseException(BaseErrorEnum.REQUEST_DATA_NULL);
            }
            if (receiveCustomer.getSuccessLogo()){
                //修改客户为已接受状态
                acceptionCustomerRecord.setUpdateStatus(acceptionCustomerVO.getAccetptionCustomerRecordId(),PushStatusEnum.RECEIVED.getCode(),UserDetailUtil.getUserDetail().getUserId(),new Date());
                int updateCount = acceptionCustomerRecordMapper.updateById(acceptionCustomerRecord);
                if (StringUtils.isEmpty(acceptionCustomerVO.getUnifiedSocialCreditCode())){
                    //接收客户后获取客户信息并入库
                    receiveCustomer.getPersonalCustomer().setUserJobNumber(UserDetailUtil.getUserDetail().getUserJobNumber());
                    boolean judgment = this.saveCustomer(receiveCustomer.getPersonalCustomer(),
                            acceptionCustomerVO.getPushSourceId(),
                            acceptionCustomerVO.getPushSoucre());
                    if (!judgment){
                        throw new BaseException("-1", "客户入库失败");
                    }
                    if (updateCount <= 0){
                        throw new BaseException("-1", "接收失败");
                    }
                    return "接收成功";
                }else {
                    //企业客户入库
                    boolean result = saveEnterpriseCustomer(receiveCustomer.getEnterpriseCustomerDetail());
                    if (!result){
                        throw new BaseException("-1", "企业客户入库失败");
                    }
                    return "接收成功";
                }
            }else {
                //修改客户为已撤回状态
                acceptionCustomerRecord.setPushCustomerStatus(PushStatusEnum.WITHDRAW.getCode());
                int updateCount = acceptionCustomerRecordMapper.updateById(acceptionCustomerRecord);
                if (updateCount <= 0){
                    throw new BaseException("-1", "接收失败");
                }
                return "客户已经被撤回";
            }
        }
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean receivePushRecord(ReceivePushRecordVO receivePushRecordVO) {
        logger.info("AcceptionCustomerServiceImpl.receivePushRecord:接收客户推送信息");
        //判断必录项
        PushCustomerRecordVO pushCustomerRecord = new PushCustomerRecordVO();
        BeanUtil.copyProperties(receivePushRecordVO,pushCustomerRecord);
        pushCustomerService.decidePushCustomerRecord(pushCustomerRecord);
        AcceptionCustomerRecord acceptionCustomerRecord = new AcceptionCustomerRecord();
        BeanUtils.copyProperties(receivePushRecordVO,acceptionCustomerRecord);
        /**用户信息与对端用户信息转换*/
        acceptionCustomerRecord.changPushInformation(receivePushRecordVO.getCooperationCompanyUserName(),
                receivePushRecordVO.getCooperationCompanyUserJobNumber(),receivePushRecordVO.getCooperationCompanyUserCertificateType(),
                receivePushRecordVO.getCooperationCompanyUserCertificateNumber(),receivePushRecordVO.getUserJobNumber(),
                receivePushRecordVO.getUserName(),receivePushRecordVO.getUserCertificateType(),receivePushRecordVO.getUserCertificateNumber(),
                new Date(),"");
        int saveCount = acceptionCustomerRecordMapper.saveAcceptionCustomerRecord(acceptionCustomerRecord);
        if (receivePushRecordVO.getProduct().size() > 0){
            int saveProduct = pushProductMapper.savePushProduct(receivePushRecordVO.getProduct(), receivePushRecordVO.getPushCustomerRecordId());
            if (saveProduct <= 0){
                return false;
            }
        }
       if (PushSourceEnum.MARKETING_CONFERENCE_PUSH.getCode().equals(receivePushRecordVO.getPushSource())
               || PushSourceEnum.MARKETING_ACTIVITY_PUSH.getCode().equals(receivePushRecordVO.getPushSource())){
           //营销会议推送客户，则添加营销会议与客户关联信息
           String userId = acceptionCustomerRecordMapper.getUserId(acceptionCustomerRecord.getUserJobNumber());
           List<CustomerDetailVO> list = new ArrayList<>();
           CustomerDetailVO customerDetail = new CustomerDetailVO();
           BeanUtils.copyProperties(acceptionCustomerRecord,customerDetail);
           customerDetail.setCustomerSource(CustomerTagEnum.RECEIVE.toInteger());
           customerDetail.setUserId(userId);
           customerDetail.setCustomerSex(Integer.parseInt(acceptionCustomerRecord.getCustomerSex()));
           customerDetail.setCustomerCertificateType(Integer.parseInt(acceptionCustomerRecord.getCustomerCertificateType()));
           list.add(customerDetail);
           if (PushSourceEnum.MARKETING_CONFERENCE_PUSH.getCode().equals(receivePushRecordVO.getPushSource())){
               //营销会议推送客户，则添加营销会议与客户关联信息
               conferenceMapper.insertConferenceCustomer(receivePushRecordVO.getPushSourceId(),userId,list);
           }else {
               //营销活动推送客户，则添加营销活动与客户关联信息
               activityMapper.insertActivityCustomer(receivePushRecordVO.getPushSourceId(),userId,list);
           }
       }
        if (saveCount <= 0){
            return false;
        }else {
            PushMessageBO message = PushMessageBO.builder().title("客户接收通知")
                    .content(acceptionCustomerRecord.getCooperationCompanyUserName()+"向你推送了一条客户信息【" + receivePushRecordVO.getCustomerName()+"】,请尽快处理")
                    .noticeJumpId(acceptionCustomerRecord.getAccetptionCustomerRecordId()).build();
            rabbitTemplate.convertAndSend(RabbitMQConstant.EXCHANGE_STR, RabbitMQConstant.MESSAGE_NOTICE,
                    RabbitMQUtils.createUserJobNumberRabbitMap(acceptionCustomerRecord.getUserJobNumber(), message,
                            BusinessMessageEnum.CUSTOMER_MESSAGE_REMINDER.getResultCode()));
            return true;
        }
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean revocationCustomer(RevocationCustomerBO revocationCustomer) {
        logger.info("AcceptionCustomerServiceImpl.revocationCustomer:接收对端撤销推送信息");
        if (StringUtils.isEmpty(revocationCustomer.getPushCustomerRecordId()) || StringUtils.isEmpty(revocationCustomer.getPushCustomerStatus())){
            return false;
        }
        AcceptionCustomerRecord acceptionCustomerRecord = new AcceptionCustomerRecord();
        BeanUtils.copyProperties(revocationCustomer,acceptionCustomerRecord);
        //条件构造器
        QueryWrapper<AcceptionCustomerRecord> query = new QueryWrapper<>();
        acceptionCustomerRecord.setUpdateTime(new Date());
        query.eq("PUSH_CUSTOMER_RECORD_ID", acceptionCustomerRecord.getPushCustomerRecordId());
        if (PushCustomerEnum.WITHDRAW.getCode().equals(revocationCustomer.getPushCustomerStatus())){
            //对端撤销推送信息后判断本端是否已接受该客户，如果接收则不可撤回
            query.isNull("UPDATE_TIME");
        }
        int updateCount = acceptionCustomerRecordMapper.update(acceptionCustomerRecord, query);
        if (updateCount <= 0) {
            return false;
        }
        return true;
    }

    @Override
    public String issueAnOrder(String policyType) {
        RestTemplate restTemplate = new RestTemplate();
        String noticeUrl = null;
        switch (policyType){
            case "1":
                //投保成功通知接口
                noticeUrl= redisUtils.get(SystemParamsEnum.NOTICE_INSURANCE_SUCCESS.getCode());
                break;
            case "2":
                //退保成功通知接口
                noticeUrl= redisUtils.get(SystemParamsEnum.NOTICE_SURRENDER_SUCCESS.getCode());
                break;
            case "3":
                //退保申请通知接口
                noticeUrl= redisUtils.get(SystemParamsEnum.NOTICE_SURRENDER_APPLICATION.getCode());
                break;
            case "4":
                //续期通知接口
                noticeUrl= redisUtils.get(SystemParamsEnum.NOTICE_RENEWAL.getCode());
                break;
            case "5":
                //满期通知接口
                noticeUrl= redisUtils.get(SystemParamsEnum.NOTICE_EXPIRATION.getCode());
                break;
            default:
                return redisUtils.get(SystemParamsEnum.JUMP_TO_APP.getCode());
        }
        String url = redisUtils.get(SystemParamsEnum.SEND_POLICY_NOTICE.getCode());
        restTemplate.getForEntity(url,Boolean.class,noticeUrl);
        return null;
    }

    @Override
    public List<Map> handleShare() {
        List<Map> shareUrl= JSONArray.parseArray(redisUtils.get(JUMP_TO_SHARE),Map.class);
        if (shareUrl == null){
            throw new BaseException("-1","请配置系统参数一键办理-分享");
        }
        return shareUrl;
    }

    @Override
    public List<Map> handleJump() {
        List<Map> jumpUrl= JSONArray.parseArray(redisUtils.get(JUMP_TO_OTHER),Map.class);
        if (jumpUrl == null){
            throw new BaseException("-1","请配置系统参数一键办理-跳转");
        }
        return jumpUrl;
    }

    @Override
    public boolean customerGoBack(GoBackCustomerVO goBackCustomer) {
        int count = acceptionCustomerRecordMapper.customerGoBack(goBackCustomer.getPushCustomerRecordId());
        if (count > 0){
            return true;
        }
        return false;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean goBackCustomer(GoBackCustomerVO goBackCustomer) {
        String unifiedSocialCreditCode = acceptionCustomerRecordMapper.getCooperationCompanyId(goBackCustomer.getAccetptionCustomerRecordId());
        int count = acceptionCustomerRecordMapper.goBackCustomer(goBackCustomer.getAccetptionCustomerRecordId());
        SendHttpRequestUtils<GoBackCustomerVO> sendHttpRequestUtils = new SendHttpRequestUtils<>();
        goBackCustomer.setPushCustomerStatus(PushCustomerEnum.NOT_RECEIVED.getCode());
        if (StringUtils.isEmpty(unifiedSocialCreditCode)){
            throw new BaseException("-1","对端统一社会信用代码为空");
        }
        if (PushSourceEnum.MARKETING_CONFERENCE_PUSH.getCode().equals(goBackCustomer.getPushSource())){
            //删除营销会议客户
            conferenceMapper.deleteConferencePersonalCustomer(goBackCustomer.getPushSourceId(),goBackCustomer.getCustomerId());
        }else {
            //删除营销活动客户
            activityMapper.deleteActivityPersonalCustomer(goBackCustomer.getPushSourceId(),goBackCustomer.getCustomerId());
        }
        Boolean isSuccess = (Boolean) sendHttpRequestUtils.sendHttpRequest(goBackCustomer, cooperationCompanyUtils.getCompanyUrl(unifiedSocialCreditCode, CompanyParameterTypeEnum.GO_BACK_CUSTOMER.getCode()));
        if (!isSuccess){
            throw new BaseException("-1","退回失败");
        }
        if (count > 0){
            return true;
        }
        return false;
    }

    /**
     * 添加客户
     * @param receiveCustomer
     * @return
     */
    @Transactional(rollbackFor = Exception.class)
    public boolean saveCustomer(PersonalCustomerBO receiveCustomer,String pushSourceId,String pushSource){
        //赋值personalCustomer
        PersonalCustomer personalCustomer = new PersonalCustomer();
        BeanUtils.copyProperties(receiveCustomer,personalCustomer);
        personalCustomer.setDefaultValue(CustomerTagEnum.RECEIVE.getCode(),UserDetailUtil.getUserDetail().getUserJobNumber());
        //根据三要素判断客户是否存在
        QueryWrapper<PersonalCustomer>queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("CUSTOMER_NAME",receiveCustomer.getCustomerName());
        queryWrapper.eq("CUSTOMER_CERTIFICATE_TYPE",receiveCustomer.getCustomerCertificateType());
        queryWrapper.eq("CUSTOMER_CERTIFICATE_NUMBER",receiveCustomer.getCustomerCertificateNumber());
        queryWrapper.eq("USER_JOB_NUMBER",UserDetailUtil.getUserDetail().getUserJobNumber());
        PersonalCustomer personalCustomers = personalCustomerMapper.selectOne(queryWrapper);
        if (personalCustomers == null){
            personalCustomer.setCustomerId(null);
            int saveCustomer = personalCustomerMapper.insert(personalCustomer);
            if (saveCustomer <= 0){
                return false;
            }
        }else {
            if (!personalCustomers.getCustomerLabel().contains(CustomerTagEnum.RECEIVE.getCode())) {
                personalCustomer.setCustomerId(personalCustomers.getCustomerId());
                personalCustomer.setCustomerLabel(personalCustomers.getCustomerLabel() + "," + CustomerTagEnum.RECEIVE.getCode());
                int saveCustomer = personalCustomerMapper.updateById(personalCustomer);
                if (saveCustomer <= 0) {
                    return false;
                }
            }
            if (!StringUtils.isEmpty(pushSourceId)){
                //如果为营销会议客户或营销活动客户则更新客户与活动/会议关联信息
                CustomerDetailVO customerDetailVO = new CustomerDetailVO();
                if (personalCustomers == null){
                    BeanUtils.copyProperties(personalCustomer,customerDetailVO);
                }else {
                    BeanUtils.copyProperties(personalCustomers,customerDetailVO);
                }
                if (PushSourceEnum.MARKETING_CONFERENCE_PUSH.getCode().equals(pushSource)){
                    conferenceMapper.updateCustomerId(pushSourceId, customerDetailVO);
                }else {
                    activityMapper.updateCustomerId(pushSourceId, customerDetailVO);
                }
            }
        }

        return true;
    }


    public boolean saveEnterpriseCustomer(EnterpriseCustomerDetailBO enterpriseCustomer){
        //根据统一社会信用代码判断本地是否存在该企业客户
        EnterpriseCustomerDetailBO enterpriseCustomerDetail = pushCustomerService.getEnterpriseCustomerByCode(enterpriseCustomer.getUnifiedSocialCreditCode(),UserDetailUtil.getUserDetail().getUserJobNumber());
        EnterpriseCustomer enterpriseCustomers = new EnterpriseCustomer();

        if (BeanUtil.isEmpty(enterpriseCustomerDetail)){
            //企业客户入库
            BeanUtils.copyProperties(enterpriseCustomer,enterpriseCustomers);
            enterpriseCustomers.setCustomerLabel(CustomerTagEnum.RECEIVE.getCode());
            enterpriseCustomers.setEnterpriseCustomerId(null);
            enterpriseCustomers.setUserJobNumber(UserDetailUtil.getUserDetail().getUserJobNumber());
            int insert = enterpriseCustomerMapper.insert(enterpriseCustomers);
            if (insert <= 0){
                return false;
            }
            return true;
        }else {
            if (!enterpriseCustomerDetail.getCustomerLabel().contains(CustomerTagEnum.RECEIVE.getCode())) {
                BeanUtils.copyProperties(enterpriseCustomer,enterpriseCustomers);
                enterpriseCustomers.setEnterpriseCustomerId(enterpriseCustomerDetail.getEnterpriseCustomerId());
                enterpriseCustomers.setCustomerLabel(enterpriseCustomerDetail.getCustomerLabel() + "," + CustomerTagEnum.RECEIVE.getCode());
                int saveCustomer = enterpriseCustomerMapper.updateById(enterpriseCustomers);
                if (saveCustomer <= 0) {
                    return false;
                }
            }
            return true;
        }
    }


    /**
     * 根据系统参数或者对端合作公司参数获取对端url
     * @param accetptionCustomerRecordId 客户接收id
     * @param cooperationParam 对端合作公司参数
     * @param systemParam 系统参数
     * @return url
     */
    private String getUrl(String accetptionCustomerRecordId,String cooperationParam,String systemParam){
        String url;
        //判断本端为银行还是保险
        //if (DistributionTypeEnum.BANK.getCode().equals(redisUtils.get(SystemParamsEnum.BANKING_OR_INSURANCE.getCode()))){
            //发送推送信息至对端合作公司
            String unifiedSocialCreditCode = acceptionCustomerRecordMapper.getCooperationCompanyId(accetptionCustomerRecordId);
            if (StringUtils.isEmpty(unifiedSocialCreditCode)){
                throw new BaseException(BaseErrorEnum.REQUEST_DATA_NULL);
            }else {
                url = cooperationCompanyUtils.getCompanyUrl(unifiedSocialCreditCode, cooperationParam);
                if (StringUtils.isEmpty(url)){
                    url = cooperationCompanyUtils.getCompanyUrlById(pushCustomerService.addRedisCompanyUrl(), unifiedSocialCreditCode, systemParam);
                }
            }
        /*}else {
            url = redisUtils.get(systemParam);
        }*/
        return url;
    }
}
